/*
 2WD Car   -L298n
*/
#include "component_l298n.h"

void car_run()
{
  int car_cmd;
  car_cmd = CAR_FORWARD;
  car_action(car_cmd);
  delay(2000);
  car_cmd = CAR_STOP;
  car_action(car_cmd);
  delay(2000);
  //
  car_cmd = CAR_BACKWARD;
  car_action(car_cmd);
  delay(2000);
  car_cmd = CAR_STOP;
  car_action(car_cmd);
  delay(2000);
  //
  car_cmd = CAR_LEFT;
  car_action(car_cmd);
  delay(2000);
  car_cmd = CAR_STOP;
  car_action(car_cmd);
  delay(2000);
  //
  car_cmd = CAR_RIGHT;
  car_action(car_cmd);
  delay(2000);
  car_cmd = CAR_STOP;
  car_action(car_cmd);
  delay(2000);
  //
  car_cmd = CAR_STOP;
  car_action(car_cmd);
};

void speed_control()
{
  int speed_level = speed_level_min;
  while (1)
  {
    speed_level += 20;
    if (speed_level > speed_level_max)
    {
      speed_level = speed_level_max;
    };
    analogWrite(leftPWM, speed_level);
    analogWrite(rightPWM, speed_level);
    car_run();
    delay(2000);
    if (speed_level == speed_level_max)
    {
      break;
    }
  };
}

void setup()
{
  setup_l298n();
  speed_control();
}

void loop()
{
}
